<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-10-29 13:43:04
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" 
-->
<template>
	<sc-VxeTable :gridEvts="gridEvents" :tablecode="'storage_query_color'" :gridOps="gridOps" ref="xGrid"
		:url="this.$API.storage.storage.list" :params="[
			{
				'material.material_nature_id': 3,
				'color_id': { value: 0, type: 'gt' }
			},
		]">
	</sc-VxeTable>
	<list-dialog v-if="dialog.listDialog" ref="listDialog" @closed="dialog.listDialog = false"
		:params="list_params"></list-dialog>
	<retail v-if="dialog.createretail" ref="createretail" @success="handleSuccess" @closed="dialog.createretail = false">
	</retail>
	<checkhc v-if="dialog.checkhc" ref="checkhc" @closed="dialog.checkhc = false">
	</checkhc>
	<deptallocation v-if="dialog.deptallocation" ref="deptallocation" @closed="dialog.deptallocation = false"
		@success="handleSuccess">
	</deptallocation>
</template>

<script>
import { ref, nextTick } from "vue";
import listDialog from "./../list";
import checkhc from "./../checkhc";
import tool from "@/utils/tool";
import retail from "@/views/market/retail/save.vue";
import deptallocation from "@/views/storage/action/deptallocation/save.vue";
// import { VXETable } from 'vxe-table';
export default {
	components: { listDialog, checkhc, retail, deptallocation },
	name: "storageQueryColor",
	setup() {
		const list_params = ref({});
		const dialog = ref({
			listDialog: false,
			createretail: false,
			checkhc: false,
			deptallocation: false,
		});
		const xGrid = ref({});
		// const dialog = ref(false);
		const listDialog = ref({});
		const createretail = ref({});
		const checkhc = ref({});
		const deptallocation = ref({});

		const gridEvents = ref({
			cellDblclick: function ({ row }) {
				dialog.value.listDialog = true;
				list_params.value = { summary_storage_id: row.id };
				nextTick(() => {
					listDialog.value.open();
				});
			},
			checkhc: function ({ button }) {
				dialog.value.checkhc = true;
				nextTick(() => {
					checkhc.value.open().setData(button.selectRecords[0]);
				});
			},
			createRetail: function ({ button }) {
				dialog.value.createretail = true;
				nextTick(() => {
					createretail.value.open().additems(button.selectRecords);
				});
			},
			createAlloc: function ({ button }) {
				dialog.value.deptallocation = true;
				nextTick(() => {
					deptallocation.value.open().additems(button.selectRecords);
				});
			},
			disable_createRetail: function (data) {
				//本部门物料才允许创建零售单
				let userInfo = tool.data.get("USER_INFO");
				let selected = data.button.selectRecords;
				return selected.length == 0
					? true
					: selected.some((v) => {
						return (
							v.location.department_id !=
							userInfo.department_id && userInfo.id != 1
						);
					});
			},
			disable_createAlloc: function (data) {
				//非本部门物料才允许创建调拨单
				let userInfo = tool.data.get("USER_INFO");
				let selected = data.button.selectRecords;
				return selected.length == 0
					? true
					: selected.some((v) => {
						return (
							v.location.department_id ==
							userInfo.department_id && userInfo.id != 1
						);
					});
			},
		});
		//
		const gridOps = {
			columns: [
				{
					field: "available_auxiliary_quantity",
					className: "blue",
				},
				{
					field: "available_quantity",
					className: "blue",
				},
				{
					field: "occupy_auxiliary_quantity",
					className: "red",
				},
				{
					field: "occupy_quantity",
					className: "red",
				},
			],
		};
		const handleSuccess = () => {
			xGrid.value.refresh();
		};
		return {
			gridEvents,
			list_params,
			dialog,
			checkhc,
			gridOps,
			listDialog,
			createretail,
			handleSuccess,
			deptallocation,
			xGrid,
		};
	},
};
</script>
